import { isURL } from '../index'

// 解析URL query部分
export const parseUrl = (url: string) => {
  if (!isURL(url)) throw new Error(`arguments[0] is not valid, required url but got ${url}`)

  const search = url.split('?')[1]

  if (!search) return {}

  return search.split('&').reduce((sum: Record<string, string>, item) => {
    const keyValue = item.split('=')

    sum[keyValue[0]] = keyValue[1] || ''

    return sum
  }, {})
}